package com.zd.controller;/**
 * @Description: OtheroutsourcingController
 * @Author:pioneer
 * @Date: 2021-07-21
 * @Version:v1.0
 */

import com.zd.service.lnter.LogisticszdServicelnter;
import com.zd.service.lnter.OtheroutsourcingServicelnter;
import com.zd.service.lnter.OutsourcingServicelnter;
import com.zd.service.lnter.WaybillServicelnter;
import com.zzg.entity.Departurelist;
import com.zzg.entity.Logistics;
import com.zzg.entity.Outsourcing;
import com.zzg.entity.Waybill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: OtheroutsourcingController 其它外包控制器
 * @Author:pioneer
 * @Date: 2021-07-21
 * @Version:v1.0
 */
@Controller
public class OtheroutsourcingController {
    @Autowired
    private OtheroutsourcingServicelnter otheroutsourcingServicelnter;
    @Autowired
    private WaybillServicelnter waybillServicelnter;
    @Autowired
    private OutsourcingServicelnter outsourcingServicelnter;
    @Autowired
    private LogisticszdServicelnter logisticszdServicelnter;

    /**
     * 查询所有其它外包信息
     * @param page 页码
     * @param limit 条目数
     * @return 对象集合
     */
    @RequestMapping("queryother")
    @ResponseBody
    public Map<String,Object> queryother(int page, int limit){
        System.out.println ("queryprice进：page"+page+"\tlimit"+limit);
        Map<String,Object> map = new HashMap<> ();
        map.put("code","");
        map.put("msg","");
        map.put("count",otheroutsourcingServicelnter.selectOtheroutsourcinglist ().size ());
        map.put("data",otheroutsourcingServicelnter.pagingqueryOtheroutsourcinglist (page,limit));
        System.out.println (map);
        return map;
    }

    /**
     * 动态条件查询所有其它外包信息
     * @param departurelist
     * @return
     */
    @RequestMapping("conditionalqueryOther")
    @ResponseBody
    public Map<String,Object> conditionalqueryOther(Departurelist departurelist){
        int page=1;
        int limit=10;
        Map<String,Object> map = new HashMap<> ();
        map.put("code","");
        map.put("msg","");
        map.put("count",otheroutsourcingServicelnter.getOtheroutsourcinglistcondition (departurelist));
        map.put("data",otheroutsourcingServicelnter.conditionqueryOtheroutsourcinglist (departurelist,page,limit));
        System.out.println (map);
        return map;
    }

    /**
     * 通过运单id查询其它外包信息
     * @param outsourcingid 运单id
     * @return 其它外包
     */
    @RequestMapping("getOtheroutsourcingByid")
    @ResponseBody
    public Departurelist getOtheroutsourcingByid(String outsourcingid){
        System.out.println ("getOtheroutsourcingByid:进"+outsourcingid);
        Departurelist departurelist=otheroutsourcingServicelnter.getOtheroutsourcingByid (outsourcingid);
        System.out.println (departurelist);
        return departurelist;
    };




    @RequestMapping("updateOtheroutsourcinglist")
    public void updateOtheroutsourcinglist(Departurelist departurelist, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        Waybill waybill= waybillServicelnter.selectWaybillByid (departurelist.getCheckenumber ());
        Outsourcing outsourcing=outsourcingServicelnter.getoutsourcegoodsid (waybill.getFreightinformation ());
        int ser=outsourcingServicelnter.updateOutsourcing (departurelist.getOutsourcingnumber(),departurelist.getSubcontractingdate(),departurelist.getOutsourcedfreight(),departurelist.getOutsourcingtype(),waybill.getFreightinformation ());
        int res=logisticszdServicelnter.updateLogistics (departurelist.getOutsourcingcompany (),departurelist.getOutsourcephone (),outsourcing.getLogisticsId ());
        if(ser>=0){
            out.write("修改成功");
        }else{
            out.write("修改失败");
        }
    }

    /**
     * 删除其他外包信息
     * @param orderno 外包单号
     * @param response
     * @throws IOException 结果集
     */
    @RequestMapping("delectother")
    public void delectother(String orderno, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        int ser=outsourcingServicelnter.delectOutsourcing (orderno);
        if(ser>=0){
            out.write("删除成功");
        }else{
            out.write("删除失败");
        }
    }

    /**
     * 查询所有物流信息
     * @return 物流集合
     */
    @RequestMapping("getLogistics")
    public List<Logistics> getLogistics(){
        List<Logistics> logisticsList= logisticszdServicelnter.selectLogistics ();
        System.out.println ("logisticsList\t"+logisticsList);
        return logisticsList;
    }
}
